package com.songlanyun.modules.message.model.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.songlanyun.common.drive.ValueObject;
import com.songlanyun.common.enums.PrivateMessageConstant;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.message.model.*;
import lombok.Data;

/**
 * app站内消息
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2021-03-04 16:05:09
 */
@Data
public class PrivateMessageVO implements ValueObject {


    /**
     * 会员ID
     */
    private Long userId;

    /**
     * 消息类型
     * 0：活动消息
     * 1：支付消息
     * 2：物流消息
     * 3：售后消息
     * 4：互动消息
     */
    private PrivateMessageConstant.MessageType type;

    /**
     * 消息内容
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String msg;

    /**
     * 消息体
     */
    private IMessageBody messageBody;

    @SuppressWarnings("all")
    public IMessageBody getMessageBody() {
        try {
            switch (type) {
                case ACTIVITY_MESSAGE:
                    return ClassConvertUtils.stringToClassSnake(this.msg, new TypeReference<ActivityMessage>() {
                    });
                case PAY_MESSAGE:
                    return ClassConvertUtils.stringToClassSnake(this.msg, new TypeReference<PayMessage>() {
                    });
                case LOGISTICS_MESSAGE:
                    return ClassConvertUtils.stringToClassSnake(this.msg, new TypeReference<LogisticsMessage>() {
                    });
                case RIGHTS_MESSAGE:
                    return ClassConvertUtils.stringToClassSnake(this.msg, new TypeReference<RightsMessage>() {
                    });
                case INTERACTION_MESSAGE:
                    return ClassConvertUtils.stringToClassSnake(this.msg, new TypeReference<InteractionMessage>() {
                    });
                case SYSTEM_MESSAGES:
                    return ClassConvertUtils.stringToClassSnake(this.msg, new TypeReference<SystemMessage>() {
                    });
                default:
                    return null;
            }
        } catch (Exception e) {
            throw new RRException("消息内容转换失败");
        }
    }


    /**
     * 消息备注
     */
    private String remark;

}
